<template>
  <div>
    <base-table :data="data" :columns="columns" ck @check="check" @approve="approve"></base-table>
  </div>
</template>

<script>
import BaseTable from '@c/table/table';
import moment from 'moment';
import { SERVER_BASE_URL, STATIS_HOST, FDS_HOST } from '@/api/config';
export default {
  components: {
    BaseTable
  },
  data () {
    return {
      data: [],
      projectType: [
        {
          key: '创新训练项目',
          value: 0
        },
        {
          key: '创业训练项目',
          value: 1
        },
        {
          key: '创业实践项目',
          value: 2
        }
        
      ],
      columns: [
        { title: ' ', type: 'index', width: 50 },
        { title: '项目名称', key: 'Name', tooltip: true },
        { title: '项目编号', key: 'No' },
        {
          title: '项目类型',
          render: (h, { row }) => {
            let str = '';
            for (let k = 0; k < this.projectType.length; k++) {
              if (row['ProjectType'] === this.projectType[k].value) {
                str = this.projectType[k].key;
                break;
              }
            }
            return h('span', {}, str);
          }
        },
        { title: '项目负责人', key: 'Creater' },
        { title: '导师', key: 'TutorName' },
        
      
        {
          title: '经费',
          render: (h, { row }) => {
            return h('span', {}, `￥${row.Budget}`);
          }
        },
        { 
          title: '截止时间',
          width: 200,
          render: (h, { row }) => {
            let start = moment(row['Start']).isValid() ? moment(row['Start']).format('YYYY/MM/DD') : 'YYYY/MM/DD';
            let end = moment(row['End']).isValid() ? moment(row['End']).format('YYYY/MM/DD') : 'YYYY/MM/DD';
            return h('span', {}, `${start} 至 ${end}`);
          }
        },
        {
          title: '申报书',
          // width: 150,
          align: 'center',
          render: (h, { row }) => {
            return h('a', {
              class: {
                download: true
              },
              attrs: {
                href: STATIS_HOST + row['WordUrl'],
                download: 'download',
                target: '_blank'
              },
              on: {
                click: (event) => {
                  event.preventDefault();
                  this.DownloadDocx(row.Id);
                }
              }
            }, '下载申报材料');
          }
        }
      ],
      total: 0
    };
  },
  methods: {
    DownloadDocx (id) {
      // console.log(id);
      this.$api.DownloadDocx({ Id: id }).then(res => {
        if (res.code === 0) {
          console.log(res);
          window.open(FDS_HOST + res.Data);
        }
      });
    },
    getall () {
      this.loading = true;
      let data = {
        busyName: 'ims_project_finish_report',
        type: '2'
      };
      this.$api.QueryBusyDoing(data).then(res => {
        // console.debug(res.Data);
        if (Array.isArray(res.Data) && res.Data.length > 0) {
          this.data = res.Data;
          this.total = this.data.length;
        }
        // if (!res.error) {
        //   this.data = res.Data;
        //   if (this.data) {
        //     this.total = this.data.length;
        //   }
        // } else {
        //   this.$Message.error(res.message);
        // }
      });
      this.loading = false;
    },
    check (rows) {
      // console.log(rows);
      if (Array.isArray(rows) && rows.length === 1) {
        this.$router.push({ name: '项目审核', params: { project: rows[0], editorable: false, type: 2, bname: 'ims_project_finish_report' } });
      } else {
        this.$Message.warning('请选择一项数据操作！');
      }
    },
    approve (rows) {
      // console.log(rows);
      if (Array.isArray(rows) && rows.length === 1) {
        this.$router.push({ name: '项目审核', params: { project: rows[0], editorable: true, type: 2, bname: 'ims_project_finish_report' } });
      } else {
        this.$Message.warning('请选择一项数据操作！');
      }
    }
  },
  mounted () {
    this.getall();
  }
};
</script>

<style scoped>

</style>